import type { Point } from './types';

export const isString = (val: unknown): val is string => typeof val === 'string';

export const noop = () => {};

// 计算斜边距离
export function calcHypotenuse(p1: Point, p2: Point) {
  return Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2);
}

// 计算向量和 (1, 0) 矢量的夹角
export function calcVectorAngle(p1: Point, p2: Point) {
  const mcp1p2 = p1.x * p2.y - p1.y * p2.x;
  const dpp1p2 = p1.x * p2.x + p1.y * p2.y;
  const radian = Math.atan2(mcp1p2, dpp1p2);
  return (radian * 180) / Math.PI;
}
